<template>
  <custom-table
    ref="table"
    :columns="tableColumns"
    :action-url="'/park/sys/user'"
    has-search
    :search-data="searchData"
    :heard-operation="heardOperation"
  >
    <template #status="{row}">
      {{ row.status===1?'启用':'停用' }}
    </template>
    <template #operations="{row}">
      <el-button type="text" @click="onEdit(row)">编辑</el-button>
      <el-button type="text" @click="onDel(row)">删除</el-button>
      <el-button type="text" @click="resetPaw(row.id)">重置密码</el-button>
    </template>
  </custom-table>
</template>

<script>
import CustomTable from '@/components/CustomTable2.vue'
import { onSecondConfirm } from '@/utils'
import { resetPswAPI } from '@/api/system'

export default {
  components: { CustomTable },
  data() {
    return {
      searchData: [
        { label: '员工姓名', type: 'input', name: 'name' }
      ],
      heardOperation: [
        { name: 'add', title: '添加员工', handler: { url: '/park/sys/user' }}
      ],
      tableColumns: [
        { label: '员工姓名', prop: 'name' },
        { label: '登录账号', prop: 'userName' },
        { label: '联系方式', prop: 'phonenumber' },
        { label: '角色', prop: 'roleName' },
        { label: '状态', prop: 'status', custom: true },
        { label: '添加时间', prop: 'createTime' },
        { label: '添加时间', prop: 'createTime' },
        { label: '操作', prop: 'operations', custom: true }
      ]
    }
  },
  methods: {
    resetPaw(id) {
      onSecondConfirm({
        content: '确定将密码重置为“123456”？',
        handler: async() => {
          await resetPswAPI(id)
          this.$message.success('重置成功!')
        }
      })
    },
    onDel(row) {
      this.$refs.table.onDelById({ title: '删除员工后，该员工账号将无法登录，是否删除？', url: '/park/sys/user' }, row)
    },
    onEdit(row) {
      this.$refs.table.handleOperation({ name: 'edit', url: '/park/sys/user', detailUrl: '/park/sys/user' }, row)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
